/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.hagopa.games.moneypool.msgs.ContentTypes.game;

import java.nio.ByteBuffer;
import org.hagopa.games.moneypool.msgs.IMsgContent;

/**
 *
 * @author Igor
 */
public class PropertyActionCT implements IMsgContent{
    private int marshalledSize = 0;
    
    private int fieldId = 0;
    private int targetCID = 0;
    private int sum = 0;

    public byte[] marshallToByte() {
                ByteBuffer dataArray = ByteBuffer.allocate(20);

		byte [] bytes = new byte[20];
		dataArray.putInt(this.fieldId);
		dataArray.putInt(this.targetCID);
		dataArray.putInt(this.sum);

		dataArray.rewind();
		this.marshalledSize = 12;
		dataArray.get(bytes,0,bytes.length);
		return bytes;
    }

    public boolean unmarshallFromByte(byte[] content)
    {
        ByteBuffer dataArray = ByteBuffer.wrap(content);
        if(null == dataArray)
        {
                return false;
        }
        dataArray.clear();

        this.fieldId = dataArray.getInt();
        System.out.println("[PropertyActionCT](unmarshallFromByte) - Field Id:" + this.fieldId);
        this.targetCID = dataArray.getInt();
        System.out.println("[PropertyActionCT](unmarshallFromByte) - Deal Partner CID:" + this.targetCID);
        this.sum = dataArray.getInt();
        System.out.println("[PropertyActionCT](unmarshallFromByte) - Sum of deal:" + this.sum);

        return true;
    }
    public int getFieldId()
    {
        return this.fieldId;
    }
    public void setFieldId(int fid)
    {
        this.fieldId = fid;
    }
    public int getPartnerCID()
    {
        return this.targetCID;
    }
    public void setPartnerCID(int pcid)
    {
        this.targetCID = pcid;
    }
    public int getOtherPropId() // prepare to AC_EXCHANGE
    {
        return this.sum;
    }

    public int getPartnershipPer() //prepare to AC_PARTNER
    {
        return this.sum;
    }
    public int getDealSum()
    {
        return this.sum;
    }
    public void setDealSum(int sum)
    {
        this.sum = sum;
    }
    public int getSize() {
        return this.marshalledSize;
    }

    public String getConcatContent() {
        String outstr = null;
        outstr = String.valueOf(this.fieldId) + String.valueOf(this.targetCID)+ String.valueOf(this.sum);
        return outstr;
    }


}
